home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 February / PCpro_2005_02.ISO / files / opensource / jEdit_4.2 / jedit42install.exe / {app} / jars / QuickNotepad.jar / QuickNotepad.class (.txt) < prev    next >
Encoding:
Java Class File  |  2004-08-26  |  4.8 KB  |  176 lines

  1. import java.awt.BorderLayout;
  2. import java.awt.Dimension;
  3. import java.awt.Font;
  4. import java.io.BufferedReader;
  5. import java.io.File;
  6. import java.io.FileNotFoundException;
  7. import java.io.FileReader;
  8. import java.io.FileWriter;
  9. import java.io.IOException;
  10. import javax.swing.JPanel;
  11. import javax.swing.JScrollPane;
  12. import org.gjt.sp.jedit.EBComponent;
  13. import org.gjt.sp.jedit.EBMessage;
  14. import org.gjt.sp.jedit.EditBus;
  15. import org.gjt.sp.jedit.GUIUtilities;
  16. import org.gjt.sp.jedit.MiscUtilities;
  17. import org.gjt.sp.jedit.View;
  18. import org.gjt.sp.jedit.jEdit;
  19. import org.gjt.sp.jedit.gui.DefaultFocusComponent;
  20. import org.gjt.sp.jedit.msg.PropertiesChanged;
  21. import org.gjt.sp.util.Log;
  22.  
  23. public class QuickNotepad extends JPanel implements EBComponent, QuickNotepadActions, DefaultFocusComponent {
  24.    private String filename;
  25.    private String defaultFilename;
  26.    private View view;
  27.    private boolean floating;
  28.    private QuickNotepadTextArea textArea;
  29.    private QuickNotepadToolPanel toolPanel;
  30.    // $FF: synthetic field
  31.    static Class class$QuickNotepad;
  32.  
  33.    public QuickNotepad(View var1, String var2) {
  34.       super(new BorderLayout());
  35.       this.view = var1;
  36.       this.floating = var2.equals("floating");
  37.       if (jEdit.getSettingsDirectory() != null) {
  38.          this.filename = jEdit.getProperty("options.quicknotepad.filepath");
  39.          if (this.filename == null || this.filename.length() == 0) {
  40.             this.filename = new String(jEdit.getSettingsDirectory() + File.separator + "qn.txt");
  41.             jEdit.setProperty("options.quicknotepad.filepath", this.filename);
  42.          }
  43.  
  44.          this.defaultFilename = this.filename;
  45.       }
  46.  
  47.       this.toolPanel = new QuickNotepadToolPanel(this);
  48.       this.add("North", this.toolPanel);
  49.       if (this.floating) {
  50.          this.setPreferredSize(new Dimension(500, 250));
  51.       }
  52.  
  53.       this.textArea = new QuickNotepadTextArea();
  54.       this.textArea.setFont(QuickNotepadOptionPane.makeFont());
  55.       this.textArea.addKeyListener(new QuickNotepad$KeyHandler(this, (QuickNotepad$1)null));
  56.       JScrollPane var3 = new JScrollPane(this.textArea);
  57.       this.add("Center", var3);
  58.       this.readFile();
  59.    }
  60.  
  61.    public void focusOnDefaultComponent() {
  62.       this.textArea.requestFocus();
  63.    }
  64.  
  65.    public String getFilename() {
  66.       return this.filename;
  67.    }
  68.  
  69.    public void handleMessage(EBMessage var1) {
  70.       if (var1 instanceof PropertiesChanged) {
  71.          this.propertiesChanged();
  72.       }
  73.  
  74.    }
  75.  
  76.    private void propertiesChanged() {
  77.       String var1 = jEdit.getProperty("options.quicknotepad.filepath");
  78.       if (!MiscUtilities.objectsEqual(this.defaultFilename, var1)) {
  79.          this.saveFile();
  80.          this.toolPanel.propertiesChanged();
  81.          this.defaultFilename = var1;
  82.          this.filename = this.defaultFilename;
  83.          this.readFile();
  84.       }
  85.  
  86.       Font var2 = QuickNotepadOptionPane.makeFont();
  87.       if (!var2.equals(this.textArea.getFont())) {
  88.          this.textArea.setFont(var2);
  89.       }
  90.  
  91.    }
  92.  
  93.    public void addNotify() {
  94.       super.addNotify();
  95.       EditBus.addToBus(this);
  96.    }
  97.  
  98.    public void removeNotify() {
  99.       this.saveFile();
  100.       super.removeNotify();
  101.       EditBus.removeFromBus(this);
  102.    }
  103.  
  104.    public void saveFile() {
  105.       if (this.filename != null && this.filename.length() != 0) {
  106.          try {
  107.             FileWriter var1 = new FileWriter(this.filename);
  108.             var1.write(this.textArea.getText());
  109.             var1.close();
  110.          } catch (IOException var2) {
  111.             Log.log(9, class$QuickNotepad == null ? (class$QuickNotepad = class$("QuickNotepad")) : class$QuickNotepad, "Could not write notepad text to " + this.filename);
  112.          }
  113.  
  114.       }
  115.    }
  116.  
  117.    public void chooseFile() {
  118.       String[] var1 = GUIUtilities.showVFSFileDialog(this.view, (String)null, 0, false);
  119.       if (var1 != null && !var1[0].equals(this.filename)) {
  120.          this.saveFile();
  121.          this.filename = var1[0];
  122.          this.toolPanel.propertiesChanged();
  123.          this.readFile();
  124.       }
  125.  
  126.    }
  127.  
  128.    public void copyToBuffer() {
  129.       jEdit.newFile(this.view);
  130.       this.view.getEditPane().getTextArea().setText(this.textArea.getText());
  131.    }
  132.  
  133.    private void readFile() {
  134.       if (this.filename != null && this.filename.length() != 0) {
  135.          Object var1 = null;
  136.  
  137.          try {
  138.             BufferedReader var6 = new BufferedReader(new FileReader(this.filename));
  139.             StringBuffer var2 = new StringBuffer(2048);
  140.  
  141.             String var3;
  142.             while((var3 = var6.readLine()) != null) {
  143.                var2.append(var3).append('\n');
  144.             }
  145.  
  146.             var6.close();
  147.             this.textArea.setText(var2.toString());
  148.          } catch (FileNotFoundException var4) {
  149.             Log.log(9, class$QuickNotepad == null ? (class$QuickNotepad = class$("QuickNotepad")) : class$QuickNotepad, "notepad file " + this.filename + " does not exist");
  150.          } catch (IOException var5) {
  151.             Log.log(9, class$QuickNotepad == null ? (class$QuickNotepad = class$("QuickNotepad")) : class$QuickNotepad, "could not read notepad file " + this.filename);
  152.          }
  153.  
  154.       }
  155.    }
  156.  
  157.    // $FF: synthetic method
  158.    static Class class$(String var0) {
  159.       try {
  160.          return Class.forName(var0);
  161.       } catch (ClassNotFoundException var2) {
  162.          throw new NoClassDefFoundError(var2.getMessage());
  163.       }
  164.    }
  165.  
  166.    // $FF: synthetic method
  167.    static boolean access$100(QuickNotepad var0) {
  168.       return var0.floating;
  169.    }
  170.  
  171.    // $FF: synthetic method
  172.    static View access$200(QuickNotepad var0) {
  173.       return var0.view;
  174.    }
  175. }
  176.